<template>
  <div id="configureTagsTop">
    <div class="search-box">
      <el-form
        ref="ruleForm"
        :inline="true"
        :model="formInline"
        class="demo-form-inline"
      >
        <el-form-item label="标签属性" prop="labelProperty" :disabled="isAbled">
          <el-select
            v-model="formInline.labelProperty"
            clearable
            placeholder=""
          >
            <el-option
              v-for="item in labelPropertyList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="标签状态" prop="enabled" :disabled="isAbled">
          <el-select
            @change="updateValue"
            v-model="formInline.enabled"
            clearable
            placeholder=""
          >
            <el-option
              v-for="item in enabledList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="分类名称" prop="labelCategoryName">
          <el-input
            clearable
            v-model="formInline.labelCategoryName"
            placeholder="请输入分类名称"
          ></el-input>
        </el-form-item>
        <el-form-item label="标签名称" prop="labelName">
          <el-input
            clearable
            v-model="formInline.labelName"
            placeholder="请输入标签名称"
          ></el-input>
        </el-form-item>
        <el-form-item label="标签ID" prop="labelId">
          <el-input
            clearable
            v-model="formInline.labelId"
            placeholder="请输入标签ID"
          ></el-input>
        </el-form-item>
        <el-form-item class="s-btn">
          <el-button
            type="success"
            icon="el-icon-search"
            @click="toSearch('ruleForm')"
          >
            查询
          </el-button>
          <el-button type="success" :disabled="isAbled" plain @click="reset">
            重置
          </el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<script>
import { sysNormalDisable } from '@utils/dictionariesFunc'
export default {
  name: 'configureTags',
  msg: '配置标签分类-顶部搜索',
  props: {
    formInline: {
      type: Object,
      default: function() {
        return {
          enabled: '', // 标签状态
          labelProperty: '', // 标签属性
          labelCategoryName: '', // 分类名称
          labelId: '', // 标签ID
          labelName: '' // 标签名称
        }
      }
    }
  },
  data() {
    return {
      isAbled: false,
      labelPropertyList: [
        {
          dictValue: '',
          dictLabel: '全部'
        }
      ], // 标签属性
      enabledList: [
        {
          dictValue: '',
          dictLabel: '全部'
        }
      ] //标签状态
    }
  },

  mounted() {
    if (this.$route.query.labelPrope) {
      this.isAbled = true
    }
    this.getStatusList()
  },
  methods: {
    updateValue() {
      this.$forceUpdate()
    },
    async getStatusList() {
      // 分类属性
      let labelPrope = await sysNormalDisable(
        'sys_labels_attribute',
        'labelPrope'
      )
      this.labelPropertyList = this.labelPropertyList.concat(labelPrope)
      // 标签状态
      let data = await sysNormalDisable('tag_status', 'label_detail_tag_status')
      this.enabledList = data.concat(this.enabledList)
      //设置默认数据
      this.setDefaultValue()
      //触发获取列表
      this.$emit('toSearch')
    },
    /*设置默认数据*/
    setDefaultValue() {
      this.formInline.enabled = this.enabledList[0].dictValue
    },
    /* 搜索 */
    toSearch(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$emit('toSearch')
        } else {
          return false
        }
      })
    },
    /* 重置 */
    reset() {
      this.$refs['ruleForm'].resetFields()
      this.setDefaultValue()
    }
  }
}
</script>

<style lang="less">
#configureTagsTop {
}
</style>
